package cn.edu.lingnan.tourism.mapper;

import cn.edu.lingnan.tourism.pojo.Route;
import cn.edu.lingnan.tourism.pojo.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface RouteMapper extends Mapper<Route> {
    //根据cid查询至少8条路线
    @Select("select * from tab_route where cid=#{cid} limit 8")
    public List<Route> selectRouteByCid(Integer cid);
    //根据给定的路线信息和当前时间来搜索相关的路线
    List<Route> getRoutesLiketStr(@Param("route") Route route,@Param("now") String now);
    //根据rname对路线进行模糊查询
    @Select("select * from tab_route where rname like CONCAT('%',#{str},'%') ")
    public List<Route> selectRouteByString(String str);
    //查询人气高的8条路线
    @Select("SELECT * FROM tab_route WHERE rid in(SELECT  result.rid FROM(SELECT rid, COUNT(uid) AS uid_count FROM tab_favorite GROUP BY rid ORDER BY uid_count DESC LIMIT 8)as result)")
    public List<Route> selectHotRoute();
    //查询tab_route表中按rdate降序排列的前8条记录。
    @Select("SELECT * from tab_route ORDER BY rdate desc LIMIT 8")
    public List<Route> selectNewRoute();
    //查询tab_route表的总数
    @Select("SELECT count(rid) from tab_route")
    public Integer selectRouteCount();
}
